package com.example.swaggerDemo.controller;
import com.example.swaggerDemo.entity.MsgEntity;

import com.example.swaggerDemo.entity.SysUserEntity;
import com.example.swaggerDemo.entity.usercount;
import com.example.swaggerDemo.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.SQLException;
import java.util.Calendar;
import java.util.List;
import java.util.Map;


@Api("系统用户接口")
@RestController
@RequestMapping(value="/User")
public class SysUserController {
    @Autowired
  private UserService SysUserDao;
    @ApiOperation(value="查询",notes="查询当前用户下属用户")
    @ResponseBody
    @RequestMapping(value="/findByupopenid",method=RequestMethod.POST)
    public Object findByupopenid(@RequestParam("upopenid") String upopenid, @RequestParam("level") String level,@RequestParam("username") String username) {
        MsgEntity msg=new MsgEntity();
        try {
            List<SysUserEntity> dto = SysUserDao.findByUpopenid(upopenid,level,username);
            if ( dto.size()>0){
                msg.msg="数据查询成功";
                msg.code=true;
                msg.object=dto;
            }
            else
            {
                msg.msg="没有查询导数据";
                msg.code=false;
                msg.object=dto;
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return msg;
    }




    @ApiOperation(value="查询",notes="查询用户")
    @ResponseBody
    @RequestMapping(value="/adminfinduser",method=RequestMethod.POST)
    public Object adminfinduser(@RequestParam("level") String level,@RequestParam("username") String username, @RequestParam("pageindex") int pagindex, @RequestParam("pagesize") int pagesize) {
        MsgEntity msg=new MsgEntity();
        try {
            List<SysUserEntity> dto = SysUserDao.adminfinduser(level,username,pagindex,pagesize);
            if ( dto.size()>0){
                msg.msg="数据查询成功";
                msg.code=true;
                msg.object=dto;
            }
            else
            {
                msg.msg="没有查询导数据";
                msg.code=false;
                msg.object=dto;
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return msg;
    }

    @ApiOperation(value="查询",notes="查询当前用户下属用户排除")
    @ResponseBody
    @RequestMapping(value="/findNoByUpopenid",method=RequestMethod.POST)
    public Object findNoByUpopenid(@RequestParam("upopenid") String upopenid, @RequestParam("level") String level,@RequestParam("username") String username) {
        MsgEntity msg=new MsgEntity();
        try {
            List<SysUserEntity> dto = SysUserDao.findNoByUpopenid(upopenid,level,username);
            if ( dto.size()>0){
                msg.msg="数据查询成功";
                msg.code=true;
                msg.object=dto;
            }
            else
            {
                msg.msg="没有查询导数据";
                msg.code=false;
                msg.object=dto;
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return msg;
    }

    @ApiOperation(value="查询",notes="查询用户信息")
    @ResponseBody
    @RequestMapping(value="/findByid",method=RequestMethod.POST)
    public Object findByid(@RequestParam("id") String id) {
        MsgEntity msg=new MsgEntity();
        try {
            SysUserEntity dto = SysUserDao.findByid(id);
            if ( dto!=null){
                msg.msg="数据查询成功";
                msg.code=true;
                msg.object=dto;
            }
            else
            {
                msg.msg="没有查询导数据";
                msg.code=false;
                msg.object=dto;
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return msg;
    }


    @ApiOperation(value="修改用户信息",notes="修改用户信息")
    @ResponseBody
    @RequestMapping(value="/update",method=RequestMethod.POST)
    public Object update(@RequestParam("username") String username, @RequestParam("mobile") String mobile, @RequestParam("address") String address, @RequestParam("userid") String userid){
        MsgEntity msg=new MsgEntity();
        int dto = SysUserDao.update(username,mobile,address,userid);
        if ( dto>0){
            msg.msg="修改成功";
            msg.code=true;
            msg.object=dto;
        }
        else
        {
            msg.msg="修改失败";
            msg.code=false;
            msg.object=dto;
        }
        return msg;
    }

    @ApiOperation(value="修改用户级别信息",notes="修改用户级别信息")
    @ResponseBody
    @RequestMapping(value="/updatusertype",method=RequestMethod.POST)
    public Object updatusertype(@RequestParam("type") String type, @RequestParam("userid") String userid){
        MsgEntity msg=new MsgEntity();
        int dto = SysUserDao.updateTypedata(type,userid);
        if ( dto>0){
            msg.msg="修改成功";
            msg.code=true;
            msg.object=dto;
        }
        else
        {
            msg.msg="修改失败";
            msg.code=false;
            msg.object=dto;
        }
        return msg;
    }


    @ApiOperation(value="修改用户上级经纪人id信息",notes="修改用户上级经纪人id信息")
    @ResponseBody
    @RequestMapping(value="/updatupopenid",method=RequestMethod.POST)
    public Object updatupopenid(@RequestParam("openid") String openid, @RequestParam("userid") String userid){
        MsgEntity msg=new MsgEntity();
        int dto = SysUserDao.updateUpopenid(openid,Integer.parseInt(userid));
        if ( dto>0){
            msg.msg="修改成功";
            msg.code=true;
            msg.object=dto;
        }
        else
        {
            msg.msg="修改失败";
            msg.code=false;
            msg.object=dto;
        }
        return msg;
    }

    @ApiOperation(value="统计用户级别信息",notes="统计用户级别信息")
    @ResponseBody
    @RequestMapping(value="/usercount",method=RequestMethod.POST)
    public Object usercount(){
        MsgEntity msg=new MsgEntity();
        List<usercount>  dto = SysUserDao.selectcount();
        if ( dto.size()>0){
            msg.msg="查询成功";
            msg.code=true;
            msg.object=dto;
        }
        else
        {
            msg.msg="没有查询到数据";
            msg.code=false;
            msg.object=dto;
        }
        return msg;
    }
}
